﻿using BasehInfoManagerModel;
using BasehInfoManagerViewModel;
using BasehInfoManagerViewModel.Common;
using BaseInfoManagerBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace zy_11._10.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]

    public class RoleManagerController : ControllerBase
    {

        //Bll以来注入
        private RoleDbBll _roleDbBll;

        public RoleManagerController(RoleDbBll roleDbBll)
        {
            _roleDbBll = roleDbBll;
        }

        //分页
        [HttpPost]
        public PagerResult<RoleDb> SearchPage(SearchModel searchModel)
        {
            return _roleDbBll.SearchPage(searchModel);
        }

        //角色添加
        [HttpPost]
        public int RoleDbAdd(RoleDbView view)
        {
            var a = _roleDbBll.RoleDbAdd(view);
            if (a == 0)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }

        //反填
        [HttpGet]
        public IActionResult GetRoleViewById(int roleId)
        {
            try
            {
                return Ok(_roleDbBll.GetRoleViewById(roleId));

            }
            catch (Exception)
            {

                throw;
            }
        }


        //修改
        [HttpPost]
        public int RoleDbUpdate(RoleDbView view)
        {
            try
            {
                var deta = _roleDbBll.RoleUpdate(view);
                if (deta)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
